package com.ruoyi.framework.reptile.webmagic.jingcai.rank.fajia;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.constant.JingCaiWebMagicConstants;
import com.ruoyi.common.enums.JcTeamType;
import com.ruoyi.framework.reptile.webmagic.jingcai.AbstractJingCaiPipeline;
import com.ruoyi.framework.reptile.webmagic.jingcai.rank.dejia.QqDeJiaRankPipeline;
import com.ruoyi.framework.reptile.webmagic.jingcai.rank.dto.QqBaseRes;
import com.ruoyi.system.domain.JcTeam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Objects;

/**
 * @author dzl
 * @Description 法甲
 * @date 2024年07月18日 18:37:00
 */
public class QqFaJiaRankPipeline extends AbstractJingCaiPipeline implements Pipeline {

    private static final Logger log = LoggerFactory.getLogger(QqFaJiaRankPipeline.class);

    @Override
    public void process(ResultItems resultItems, Task task) {
        String jcData = resultItems.get("jcData").toString();
        QqBaseRes qqBaseRes = JSON.parseObject(jcData, QqBaseRes.class);
        if (Objects.isNull(qqBaseRes)) {
            log.info("爬取到的法甲数据为空，直接返回");
            return;
        }
        JcTeam queryParam = new JcTeam();
        queryParam.setSeason(JingCaiWebMagicConstants.SEASON);
        queryParam.setType(JcTeamType.TYPE_DJ.getType());
        handleJcTeam(queryParam, buildUpdateListByQq(qqBaseRes, JingCaiWebMagicConstants.SEASON, JcTeamType.TYPE_FJ.getType()));
    }
}
